home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / Unsupported Libraries / Text3D.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  5.0 KB  |  222 lines  |  [TEXT/MPS ]

  1. /******************************************************************************
  2.  **                                                                             **
  3.  **     Module:        Text3D.c                                                 **
  4.  **                                                                          **
  5.  **                                                                          **
  6.  **     Purpose:     Create a general polygon from character outlines          **
  7.  **                                                                          **
  8.  **                                                                          **
  9.  **                                                                          **
  10.  **     Copyright (C) 1992-1995 Apple Computer, Inc.  All rights reserved.     **
  11.  **                                                                          **
  12.  **                                                                          **
  13.  *****************************************************************************/
  14. #include "QD3D.h"
  15. #include "Text3D.h"
  16.  
  17. #if defined(NOGX) && NOGX
  18.  
  19. TQ3GroupObject ReadText(
  20.     void)
  21. {
  22.     return(NULL);
  23. }
  24.  
  25. TQ3GroupObject MakeText(
  26.     char    *str)
  27. {
  28.     if (str) {
  29.         int foo;
  30.         
  31.         foo = 42;
  32.     }
  33.     return (NULL);
  34. }
  35.  
  36. #else /* !defined(NOGX) || !NOGX */
  37.  
  38. #include <stdlib.h>
  39. #include <stdio.h>
  40. #include <string.h>
  41.  
  42. #include <Dialogs.h>
  43. #include <Fonts.h>
  44. #include <Memory.h>
  45. #include <Menus.h>
  46. #include <OSUtils.h>
  47. #include <SegLoad.h>
  48. #include <TextEdit.h>
  49. #include <Files.h>
  50. #include <StandardFile.h>
  51.  
  52. #ifdef applec
  53. # include <Strings.h>
  54. #endif /* applec */
  55. #ifdef THINK_C
  56. # include <pascal.h>
  57. #endif /* THINK_C */
  58.  
  59. #include "QD3DShader.h"
  60. #include "QD3DTransform.h"
  61. #include "QD3DStyle.h"
  62. #include "QD3DView.h"
  63. #include "QD3DMath.h"
  64. #include "QD3DSet.h"
  65. #include "QD3DGroup.h"
  66. #include "QD3DGeometry.h"
  67.  
  68. #include "GXLayout.h"
  69. #include "FontLibrary.h"
  70. #include "GraphicsLibraries.h"
  71.  
  72. /* 
  73.  *  This needs to be after all Escher and toolbox includes 
  74.  */
  75. #include "OffscreenLibrary.h"
  76. #include "StorageLibrary.h"
  77.  
  78. #include "LayoutLibrary.h"
  79. #include "LayoutFeatureConstants.h"
  80.  
  81.  
  82. /*===========================================================================*\
  83.  *
  84.  *    Routine:    ReadText()
  85.  *
  86.  *    Comments:    
  87.  *
  88. \*===========================================================================*/
  89.  
  90. TQ3GroupObject ReadText(
  91.     void)
  92. {
  93.     char     str[256];
  94.     
  95.     TextFont(symbol);
  96.     TextFace(italic);
  97.     TextSize(9);
  98.     TextMode(srcCopy);
  99.     
  100.     strcpy(str, "QuickDraw 3D");
  101.     return(MakeText(str));
  102. }
  103.  
  104.  
  105. /*===========================================================================*\
  106.  *
  107.  *    Routine:    MakeText()
  108.  *
  109.  *    Comments:    
  110.  *
  111. \*===========================================================================*/
  112.  
  113. TQ3GroupObject MakeText(
  114.     char    *str)
  115. {
  116.     gxPoint             strPosition;
  117.     gxShape             stringShape;
  118.     long                 size, numContours;
  119.     gxPolygons             *blog;
  120.     gxPolygon             *poly;
  121.     char                 *pp;
  122.     unsigned long         i, b, c;
  123.  
  124.     TQ3GroupObject     group;
  125.     TQ3ColorRGB             col;
  126.     gxRectangle            rect = {
  127.                                     IntToFixed(0.0), 
  128.                                     IntToFixed(0.0), 
  129.                                     IntToFixed(100.0), 
  130.                                     IntToFixed(-100.0)
  131.                                 };
  132.     gxRectangle         rect2 = {
  133.                                     IntToFixed(30.0), 
  134.                                     IntToFixed(-30.0), 
  135.                                     IntToFixed(60.0), 
  136.                                     IntToFixed(-60.0)};
  137.  
  138.  
  139.     TQ3GeneralPolygonData gp;
  140.     TQ3GeometryObject     generalPoly;
  141.     
  142.     gxRunFeature        features[1];
  143.     
  144.     strPosition.x = 0;
  145.     strPosition.y = 0;
  146.     stringShape = NewCString(str, &strPosition);
  147.     GXSetShapeFont(stringShape, FindCNameFont(gxFamilyFontName, "Apple Chancery"));
  148.     GXSetShapeTextSize(stringShape, IntToFixed(48));
  149.     GXSetShapeFill(stringShape, gxSolidFill);
  150.     
  151.     GXSetShapeType(stringShape, gxLayoutType);
  152.     features[0].featureType = designComplexityType;
  153.     features[0].featureSelector = designLevel3Selector;
  154.     GXSetShapeRunFeatures(stringShape, 1, features);
  155.     
  156.     GXSetStyleCurveError(GXGetShapeStyle(stringShape), FloatToFixed(1.5));    
  157.      GXSetShapeCurveError(stringShape, FloatToFixed(1.5));
  158.  
  159.     GXSetShapeType(stringShape, gxPolygonType);
  160.  
  161.     numContours = GXCountShapeContours(stringShape);
  162.     size = GXGetPolygons(stringShape, NULL);
  163.     if (!(blog = (gxPolygons *) malloc (size))) {
  164.         return(NULL);
  165.     }
  166.     GXGetPolygons(stringShape, blog);
  167.     GXDisposeShape(stringShape);
  168.  
  169.     group = Q3OrderedDisplayGroup_New();
  170.     Q3ColorRGB_Set(&col, 1.0, 0.0, 0.0);
  171.  
  172.     gp.numContours = blog->contours;
  173.     gp.generalPolygonAttributeSet = Q3AttributeSet_New();
  174.     
  175.     Q3AttributeSet_Add(
  176.         gp.generalPolygonAttributeSet, 
  177.         kQ3AttributeTypeDiffuseColor, 
  178.         (const void *) &col);
  179.  
  180.     if (!(gp.contours = 
  181.         (TQ3GeneralPolygonContourData *) malloc(gp.numContours * sizeof(TQ3GeneralPolygonContourData)))) {
  182.         return(NULL);
  183.     }
  184.  
  185.     pp = (char *)&blog->contour[0].vectors;
  186.     for (i = 0; i < blog->contours; i++) {
  187.         poly = (gxPolygon *)pp;
  188.         pp += sizeof(long);
  189.         gp.contours[i].numVertices = poly->vectors;
  190.  
  191.         if (!(gp.contours[i].vertices = (TQ3Vertex3D *)
  192.                         malloc(poly->vectors * sizeof(TQ3Vertex3D)))) {
  193.             return (NULL);
  194.         }
  195.  
  196.         for (b = 0, c = poly->vectors-1; b < poly->vectors; b++, c--) {
  197.             gp.contours[i].vertices[c].point.x = 
  198.                                 (float)FixedToFloat(poly->vector[b].x) / 20.0;
  199.             gp.contours[i].vertices[c].point.y = 
  200.                                 (float)-FixedToFloat(poly->vector[b].y) / 20.0;
  201.             gp.contours[i].vertices[c].point.z = 0.0;
  202.             gp.contours[i].vertices[c].attributeSet = NULL;
  203.             pp += sizeof(gxPoint);
  204.         }
  205.     }
  206.  
  207.     generalPoly = Q3GeneralPolygon_New(&gp);
  208.     Q3Group_AddObject(group, generalPoly);
  209.  
  210.     Q3Object_Dispose(gp.generalPolygonAttributeSet);
  211.     Q3Object_Dispose(generalPoly);
  212.  
  213.     for (i = 0; i < blog->contours; i++) {
  214.         free(gp.contours[i].vertices);
  215.     }
  216.     free(gp.contours);
  217.     
  218.     return(group);
  219. }
  220.  
  221. #endif /* defined(NOGX) && NOGX */
  222.